package mul_thread;

import lombok.SneakyThrows;

/**
 * -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly
 * https://blog.csdn.net/wangming520liwei/article/details/81561922
 */
public class VolatileTest {
    public static volatile boolean flag = false;

    public static void main(String[] args) {
        new Thread() {
            public void run() {
                System.out.println("thread-1 is start");
                while (!flag) {
                }
                System.out.println("thread-1 is end");
            }
        }.start();

        new Thread() {
            @SneakyThrows
            public void run() {
                System.out.println("thread-2 is start");
                flag = true;
                System.out.println("thread-2 is end");
            }
        }.start();
    }
}
